#include<bits/stdc++.h>
using namespace std;

int pd(int x){
    for(int i = 2;i<=sqrt(x);i++){
        if(x % i == 0) return 0;
    }
    return 1;
}
int reverse_int(int x){
    int origin = x;
    int sum = 0;
    while (x != 0)
    {
        int tmp = x % 10;
        sum = sum*10+tmp;
        x/=10;
    }
    return origin == sum;
    
}
int main(){
    int a,b;
    cin>>a>>b;
    if(a < 5){
        return 0;
    }
    //先找质数，再判断是不是回文数
    for(int i = a;i < b;i++){
        if(reverse_int(i)){
            if(pd(i)){
            printf("%d\n",i);
            }
        }
    }



    return 0;
}